/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.DataSourceBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.SoapFaultException;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AttributeClass;
/*     */ import com.zimbra.cs.account.DataSource;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.admin.message.ModifyDataSourceRequest;
/*     */ import com.zimbra.soap.admin.type.DataSourceInfo;
/*     */ import com.zimbra.soap.admin.type.DataSourceType;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ModifyDataSource
/*     */   extends AdminDocumentHandler
/*     */ {
/*  43 */   private static final String[] TARGET_ACCOUNT_PATH = { "id" };
/*     */   
/*  45 */   protected String[] getProxiedAccountPath() { return TARGET_ACCOUNT_PATH; }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean domainAuthSufficient(Map context)
/*     */   {
/*  52 */     return true;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   public boolean defendsAgainstDelegateAdminAccountHarvesting()
/*     */   {
/*  60 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException
/*     */   {
/*  65 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  66 */     Provisioning prov = Provisioning.getInstance();
/*  67 */     ModifyDataSourceRequest req = (ModifyDataSourceRequest)JaxbUtil.elementToJaxb(request);
/*  68 */     String id = req.getId();
/*  69 */     Account account = prov.get(Key.AccountBy.id, id, zsc.getAuthToken());
/*  70 */     defendAgainstAccountOrCalendarResourceHarvesting(account, Key.AccountBy.id, id, zsc, Rights.Admin.R_adminLoginAs, Rights.Admin.R_adminLoginCalendarResourceAs);
/*     */     
/*     */ 
/*  73 */     DataSourceInfo dataSource = req.getDataSource();
/*  74 */     Map<String, Object> attrs = dataSource.getAttrsAsOldMultimap();
/*     */     
/*  76 */     String dsId = dataSource.getId();
/*  77 */     DataSource ds = prov.get(account, Key.DataSourceBy.id, dsId);
/*  78 */     if (ds == null) {
/*  79 */       throw ServiceException.INVALID_REQUEST("Cannot find data source with id=" + dsId, null);
/*     */     }
/*     */     
/*  82 */     DataSourceType type = ds.getType();
/*     */     
/*     */ 
/*  85 */     if (isDomainAdminOnly(zsc))
/*     */     {
/*     */ 
/*  88 */       AttributeClass klass = getAttributeClassFromType(type);
/*  89 */       checkModifyAttrs(zsc, klass, attrs);
/*     */     }
/*     */     
/*  92 */     ZimbraLog.addDataSourceNameToContext(ds.getName());
/*     */     
/*  94 */     prov.modifyDataSource(account, dsId, attrs);
/*     */     
/*  96 */     Element response = zsc.createElement(AdminConstants.MODIFY_DATA_SOURCE_RESPONSE);
/*  97 */     return response;
/*     */   }
/*     */   
/*     */   static AttributeClass getAttributeClassFromType(DataSourceType type) {
/* 101 */     if (type == DataSourceType.pop3)
/* 102 */       return AttributeClass.pop3DataSource;
/* 103 */     if (type == DataSourceType.imap)
/* 104 */       return AttributeClass.imapDataSource;
/* 105 */     if (type == DataSourceType.rss)
/* 106 */       return AttributeClass.rssDataSource;
/* 107 */     if (type == DataSourceType.gal) {
/* 108 */       return AttributeClass.galDataSource;
/*     */     }
/* 110 */     return AttributeClass.dataSource;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 115 */     relatedRights.add(Rights.Admin.R_adminLoginAs);
/* 116 */     relatedRights.add(Rights.Admin.R_adminLoginCalendarResourceAs);
/* 117 */     notes.add("If the target is an account, need the adminLoginAs right; If the target is a calendar resource, need the R_adminLoginCalendarResourceAs right.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/ModifyDataSource.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */